package com.lianzhihui.romeex.adapter;

import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.bean.SaveAddressInfo;

import java.util.List;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.adapter
 * @ClassName: MessageActivityAdapter
 * @Description: java类作用描述
 * @Author: zhanghong
 * @CreateDate: 2020/11/2 15:02
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/2 15:02
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class AddressActivityAdapter extends BaseQuickAdapter<SaveAddressInfo.Address, BaseViewHolder> {
    private Context context;

    public AddressActivityAdapter(Context context, @Nullable List<SaveAddressInfo.Address> data) {
        super(R.layout.item_address, data);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SaveAddressInfo.Address item) {
        if (item == null) {
            return;
        }
        helper.setText(R.id.message_title, item.getUserCurrencyName())
                .setText(R.id.message_content, item.getAddress());
        if (item.getUserCurrencyName().contains("USDT")) {
            helper.setImageResource(R.id.icon, R.drawable.icon_logo_usdt);
        } else if (item.getUserCurrencyName().contains("RET")) {
            helper.setImageResource(R.id.icon, R.mipmap.icon_rex_40);
        } else {
            helper.setImageResource(R.id.icon, R.mipmap.icon_rusd_40);
        }
        TextView message = helper.getView(R.id.message_content);
        ImageView iv_copy = helper.getView(R.id.iv_copy);
        iv_copy.setOnClickListener(v -> {
            ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            cm.setText(message.getText().toString().trim());
            Toast.makeText(context, context.getResources().getString(R.string.toast_copy_success), Toast.LENGTH_SHORT).show();
        });
        if (item.getNote().isEmpty()) {
            View view = helper.getView(R.id.message_date);
            view.setVisibility(View.GONE);
        } else {
            helper.setText(R.id.message_date, item.getNote());
        }
    }
}
